package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao extends BaseStudentDao {
    private static ArrayList<Student> stus = new ArrayList<>();
    static {
        Student stu1 = new Student("12","张三","24","1996-5-1");
        Student stu2 = new Student("15","李四","30","1990-6-1");
        stus.add(stu1);
        stus.add(stu2);

    }
//添加
    @Override
    public boolean addStudent(Student st) {
     stus.add(st);
     return true;
    }
//查找
    public Student[] findAllStudent() {
        Student[] students = new Student[stus.size()];
        for (int i = 0; i < students.length; i++) {
            students[i] = stus.get(i);
        }
        return students;
    }
//删除
    public void deleteStudentByld(String id) {
        int index = getIndex(id);
        stus.remove(index);

    }
//修改
    public void updateStudent(String id1, Student st) {
           int index = getIndex(id1);
           stus.set(index,st);
        }
//查看索引
  public int getIndex(String id){
        int index = -1 ;
      for (int i = 0; i < stus.size(); i++) {
          if (stus.get(i) != null && stus.get(i).getId().equals(id)){
              index=i;
              break;
          }
      }
      return index;
  }
}